package es.seam.myebay;

import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;

import es.seam.myebay.model.Bid;

@Name("bidq")
@AutoCreate
public class BidQuery {

    @In(value = "entityManager")
    private EntityManager em;
    
    public Bid readBid(int id) {
        Bid bid = (Bid) em.find(Bid.class, id);
        return bid;
    }
    
    public List<Bid> lastBids(int num) {
        String ejbql = "SELECT b FROM Bid b ORDER BY b.id DESC";
        Query query = em.createQuery(ejbql).setMaxResults(10);
        List<Bid> list = query.getResultList();
        return list;
    }
    
    public List<Bid> bidsFromDate(Date from) {
        // TODO
        return null;
    }
    
}
